package org.point.dao.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.CreditsRuleDao;import org.point.domain.CreditsRule;
import org.point.domain.CreditsType;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: CreditsRuleDaoImpl
 * @Description: TODO(积分规则数据实现类)
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月22日 下午11:53:49
 *
 */
@Repository("creditsRuleDao")
public class CreditsRuleDaoImpl extends BaseDaoImpl<CreditsRule, Serializable> implements CreditsRuleDao {

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>Title: </p>  
	 * <p>Description: </p>
	 */
	public CreditsRuleDaoImpl() {
		namespace = super.getNamespace();
	}
	
	// 根据会员单位查询积分规则信息列表
	public static final String SQLID_FINDCRFORMEM = "find_CR_For_Mem";
	public static final String SQLID_FINDCRFORMEMPAGE = "find_CR_For_Mem_Page";
	// 根据会员单位查询积分规则记录数
	public static final String SQLID_COUNTCRFORMEMPAGE = "count_CR_For_Mem";
	// 会员单位新增积分规则信息
	public static final String SQLID_INSERTCR = "insert_CR";
	// 修改积分规则状态
	public static final String SQLID_UPDSTATUS = "upd_Status";
	
	private static final String SQLID_DELCRS = "delCRs";
	
	private static final String SQLID_SEARCHFORCR = "searchForCR";
	private static final String SQLID_DELCRSBYID = "delCRsByid";

	public List<CreditsRule> findCRForMem(Map<String, Object> map) {
		List<CreditsRule> records = getSqlSession().selectList(namespace + SQLID_FINDCRFORMEM, map);
		return records;
	}

	public List<CreditsRule> findCRForMem(DoPage<CreditsRule> page) {
		List<CreditsRule> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_FINDCRFORMEMPAGE, page);
		} catch (Exception e) {
			e.printStackTrace();
			// throw new RuntimeException("积分规则查询错误！", e);
		}
		return records;
	}

	public Integer countCRForMem(DoPage<CreditsRule> page) {
		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_COUNTCRFORMEMPAGE, page);
		} catch (Exception e) {
			e.printStackTrace();
			// throw new RuntimeException("积分规则查询记录数错误！", e);
		}
		return result;
	}

	public Integer insertCR(CreditsRule record) {
		Integer result = 0;
		try {
			result = getSqlSession().insert(namespace + SQLID_INSERTCR, record);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public Integer updStatus(Map<String, Object> map) {
		Integer result = getSqlSession().update(namespace + SQLID_UPDSTATUS, map);
		return result;
	}

	public Integer delCRs(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELCRS,map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public CreditsRule searchForCT(Map<String, Object> map) {
		CreditsRule record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_SEARCHFORCR, map);
		} catch (Exception e) {
			throw new RuntimeException("积分规则分类查询错误！", e);
		}
		return record;
	}

	public Integer delCRbyId(Map<String, Object> map) {
		Integer result = 0;
		try {
			 result = getSqlSession().update(namespace+SQLID_DELCRSBYID, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	
}
